<?php

// 本类由系统自动生成，仅供测试用途
class BooklistAction extends Action {

    public function index() {
        $userorder = D('UserOrderView');
        $userorderlist = $userorder->order('ordertime desc')->select();
        foreach ($userorderlist as $val) {
            $goodsArray = json_decode($val['orderdetail'], TRUE);           
            foreach ($goodsArray['order'] as $key =>$goodsval){
                if($goodsval['goodsnum']=='0'){
                    unset($goodsArray['order'][$key]);
                }
            }
            $orderArray = $goodsArray;
            $orderArray['orderid'] = $val['id'];
            $orderArray['userid'] = $val['userid'];
            $orderArray['datetime'] = $val['ordertime'];
            $orderArray['username'] = $val['username'];
            $orderArray['name'] = $val['name'];
            $orderArray['phone'] = $val['phone'];
            $orderArray['address'] = $val['address'];
            $myorderlistArray[] = $orderArray;
        }
        $goodsorder = M('goodsorder');
        $condition['isnew'] = '1';
        $data['isnew'] = '0';
        $goodsorder->where($condition)->save($data);
        //var_dump($myorderlistArray);
        $this->assign('myorderlistArray', $myorderlistArray);
        $this->display();
    }
    
    public function delete_order(){
        $goodsorder = M('goodsorder');
        $condition['id'] = $_POST['orderid'];
        $result = $goodsorder->where($condition)->delete();
        if ($result) {
            $this->success('订单删除成功！');
        } else {
            $this->error('订单删除失败！');
        }
    }

}